ForeignName, ForeignTable, and Table Properties Example

This example shows how the Table, ForeignTable, and ForeignName properties define the terms of a Relation between two tables.

Sub ForeignNameX()

    Dim dbsNorthwind As Database
    Dim relLoop As Relation

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")

    Debug.Print "Relation"
    Debug.Print "        Table - Field"
    Debug.Print "  Primary (One) ";
    Debug.Print ".Table - .Fields(0).Name"
    Debug.Print "  Foreign (Many)  ";
    Debug.Print ".ForeignTable - .Fields(0).ForeignName"

    ' Enumerate the Relations collection of the Northwind 
    ' database to report on the property values of 
    ' the Relation objects and their Field objects.
    For Each relLoop In dbsNorthwind.Relations
        With relLoop
            Debug.Print
            Debug.Print .Name & " Relation"
            Debug.Print "        Table - Field"
            Debug.Print "  Primary (One) ";
            Debug.Print .Table & " - " & .Fields(0).Name
            Debug.Print "  Foreign (Many)  ";
            Debug.Print .ForeignTable & " - " & _
                .Fields(0).ForeignName
        End With
    Next relLoop

    dbsNorthwind.Close

End Sub